#!/bin/bash

# 定义备份目录
BACKUP_DIR="/path/backup"

# 创建备份目录
mkdir -p $BACKUP_DIR

# 备份所有表的规则
sudo iptables-save > $BACKUP_DIR/iptables-all.rules

# 备份 filter 表的规则
sudo iptables-save -t filter > $BACKUP_DIR/iptables-filter.rules

# 备份 nat 表的规则
sudo iptables-save -t nat > $BACKUP_DIR/iptables-nat.rules

# 备份 mangle 表的规则
sudo iptables-save -t mangle > $BACKUP_DIR/iptables-mangle.rules

# 备份 raw 表的规则
sudo iptables-save -t raw > $BACKUP_DIR/iptables-raw.rules

echo "iptables rules backup completed successfully."